home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-29 | 7.8 KB | 289 lines | [TEXT/KAHL] |
- /****
- * CNDCamera.cp
- *
- * Methods for a persistent camera class.
- *
- * Copyright © 1992 NeoLogic Systems. All rights reserved.
- *
- ****/
-
- #include "NeoTypes.h"
- #include CNeoStreamH
- #include CNeoMetaClassH
- #include CNeoSelectH
- #include CNeoDatabaseH
- #include CNeoNodeH
- #include "CNDCamera.h"
-
- #ifndef NeoInherited
- #define NeoInherited CNeoPersist
- #endif
-
- short CNDCamera::FCameraCnt = 0;
- NeoID CNDCamera::FCamMenu2IDTable[kMaxCameras] = {0};
-
- CNDCamera::CNDCamera(const CNeoString &aName, const short aShutterCnt, const short *aSpeeds)
- {
- short index;
-
- fShutterCount = aShutterCnt;
- for (index = 0; index <fShutterCount; index++)
- fShutters[index] = aSpeeds[index];
- fName = aName;
- }
-
- // Return the class ID for this kind of object
- NeoID CNDCamera::getClassID(void) const
- {
- return kNDCameraID;
- }
-
- /*
- * Allocate and initialize a new instance.
- */
- CNeoPersist *CNDCamera::New(void)
- {
- CNDCamera * object;
-
- object = new CNDCamera("\p", 0, nil);
-
- return object;
- }
-
- /*
- * Overriding this virtual method from the parent is an optimization which allows us
- * to avoid calling GetHandleSize().
- */
- #pragma segment NeoInfo
- long CNDCamera::getLength(void) const
- {
- return sizeof(CNDCamera);
- }
-
- /*
- * This method returns the amount of file space the object occupies in the file. It
- * differs from the getLength() in that getLength returns the size of the object in
- * memory.
- */
- #pragma segment NeoInfo
- long CNDCamera::getFileLength(void) const
- {
- return kNeoPersistFileLength + sizeof(fShutterCount) + sizeof(fShutters) + sizeof(fName);
- }
-
- /* ****************************************************************** */
- /** I/O Methods **/
- /* ****************************************************************** */
-
- /*
- * The readObject method is used to read in the permanent data members of the
- * object from the given stream. In most cases, this method operates without concern
- * for the type of stream the data values are coming from. As a result, this method
- * is capable of reading from such diverse sources as the data fork of a file, a
- * resource fork, an AppleEvent, the clipboard, a memory block, and so on.
- *
- * The aTag argument indicates how much information to read from the stream.
- * It is sometimes sufficient to read in a minimum amount of data and have all
- * other data be read in on demand. Other times it is necessary to read all the
- * data immediately as the stream may not be available later.
- *
- * The two tag values that are currently used are kNeoObjectTag and kNeoAllTag.
- *
- * The value kNeoObjectTag means that only those values of immediate interest
- * need to be read from the stream, though implementations of readObject may read
- * in additional data member values if they wish.
- *
- * The value kNeoAllTag indicates that all data member values for this class
- * should be read in to the stream.
- */
- #pragma segment NeoRead
- void CNDCamera::readObject(CNeoStream *aStream, const NeoTag aTag)
- {
- short index;
-
- NeoInherited::readObject(aStream, aTag);
-
- fShutterCount = aStream->readShort(pShutterCount);
- if (fShutterCount) {
- aStream->openList(pCameraShutters);
- for (index = 0; index < fShutterCount; index++) {
- fShutters[index] = aStream->readShort();
- }
- aStream->closeList();
- }
-
- aStream->readNativeString(fName, sizeof(fName), pName);
- }
-
- /*
- * The writeObject method is used to write to the permanent data members of the
- * object from the given stream. In most cases, this method operates without concern
- * for the type of stream the data values are coming from. As a result, this method
- * is capable of writing to such diverse sources as the data fork of a file, a
- * resource fork, an AppleEvent, the clipboard, a memory block, and so on.
- *
- * The aTag argument indicates how much information to write to the stream.
- * It is sometimes sufficient to write out only those parts that are dirty. Other
- * times it is necessary to write all the data, as when doing Save As operation
- * or when communicating an object's complete state across and RPC channel.
- *
- * The two tag values that are currently used are kNeoObjectTag and kNeoAllTag.
- *
- * The value kNeoObjectTag means that only those values of immediate interest
- * need to be written to the stream, though implementations of writeObject may
- * write out additional data member values if they wish.
- *
- * The value kNeoAllTag indicates that all data member values for this class
- * should be writen out to the stream.
- */
- #pragma segment NeoWrite
- void CNDCamera::writeObject(CNeoStream *aStream, const NeoTag aTag)
- {
- short index;
-
- NeoInherited::writeObject(aStream, aTag);
-
- aStream->writeShort(fShutterCount, pShutterCount);
- if (fShutterCount) {
- aStream->openList(pCameraShutters);
- for (index = 0; index < fShutterCount; index++)
- aStream->writeShort(fShutters[index]);
- aStream->closeList();
- }
-
- aStream->writeNativeString(fName, sizeof(fName), pName);
- }
-
- /** Search Methods **/
- /*
- * Once an object is made permanent it can continue be treated like any other object,
- * including being disposed of. While disposing of an object involves elliminating a
- * reference to it (and in the process, deleteing it from memory), disposing does not
- * affect object's permanent state in the file.
- *
- * Locating a permanent object in a file is very easy. In order to identify the
- * object (or objects) of interest its class and identity must be given. FindByID()
- * is also capable of using the specified class as a base class so that it and all
- * subclasses of the base class is searched to locate the object. If the given
- * identity is ambiguous, then the search may find more than one object. Passing
- * FindByID() an array will allow this function to return a list of all objects
- * found.
- */
- #pragma segment NeoSearch
- CNDCamera *CNDCamera::FindByName(CNeoDatabase *aDataBase, const CNeoString &aName)
- {
- CNeoNameSelect key(aName);
- CNDCamera * camera;
-
- camera = (CNDCamera *)aDataBase->findObject(kNDCameraID, &key, FALSE);
-
- return camera;
- }
-
- /** Access Methods **/
- short CNDCamera::addShutterSpeed(const short aSpeed)
- {
- short index;
- short j;
-
- NeoAssert(fShutterCount < kShutterMax);
-
- if (aSpeed > fShutters[fShutterCount])
- fShutters[++fShutterCount] = aSpeed;
- else {
- for (index = 0; index < fShutterCount; index++) {
- if (fShutters[index] == aSpeed)
- break; // This speed already exists in the list
- if (fShutters[index] > aSpeed) {
- for (j = fShutterCount; j >= index; j--)
- fShutters[j] = fShutters[j +1];
- fShutters[index] = aSpeed;
- fShutterCount++;
- }
- }
- }
-
- setDirty();
-
- return fShutterCount;
- }
-
- void CNDCamera::ClearCameraTable(void)
- {
- FCameraCnt = 0;
- }
-
- void CNDCamera::deleteShutterSpeed(const short aIndex)
- {
- short index;
-
- NeoAssert(aIndex < fShutterCount);
-
- if (aIndex < fShutterCount -1)
- for (index = aIndex; index < fShutterCount; index++)
- fShutters[index] = fShutters[index +1];
-
- fShutterCount--;
- setDirty();
- }
-
- NeoID CNDCamera::GetCameraID(const short aIndex)
- {
- return FCamMenu2IDTable[aIndex -2];
- }
-
- void CNDCamera::getName(CNeoString &aName)
- {
- aName = fName;
- if (aName[0] > 32)
- aName[0] = 32;
- }
-
- short CNDCamera::getShutterCount(void)
- {
- return fShutterCount;
- }
-
- short CNDCamera::getShutter(const short aIndex)
- {
- NeoAssert(aIndex < fShutterCount);
-
- return fShutters[aIndex];
- }
-
- void CNDCamera::setName(const CNeoString &aName)
- {
- fName = aName;
- if (fName[0] > 32)
- fName[0] = 32;
-
- setDirty();
- }
-
- /** Search Methods **/
- /*
- * This function is applied to every camera in the file. It adds the camera to
- * the cameras popup menu
- */
- void *CNDCamera::MakeCameraMenu(CNeoNode *aNode, const short aIndex, const NeoLockType aLock, void *aParam)
- {
- MenuHandle menu = (MenuHandle)aParam;
- CNDCamera * camera;
- CNeoString name;
-
- if (aIndex < 0)
- camera = (CNDCamera *)aNode;
- else
- NeoFailNil(camera = (CNDCamera *)aNode->getObject(aIndex));
-
- if (FCameraCnt < kMaxCameras) {
- FCamMenu2IDTable[FCameraCnt] = camera->fID;
- FCameraCnt++;
- camera->getName(name);
- AppendMenu(menu, name);
- }
-
- return nil;
- }
-
-